<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <title>融云IM</title>
    <link rel="stylesheet" href="${base}/im.css">
</head>
<body>
<div id="rcs-app"></div>
</body>
<!--
SDK 文档：http://www.rongcloud.cn/docs/web.html#sdk
-->
<script src="//cdn.ronghub.com/RongIMLib-2.3.0.min.js"></script>
<!-- <script src="./libs/RongEmoji.js"></script> -->
<script src="//cdn.ronghub.com/RongEmoji-2.2.6.min.js"></script>
<script src="${base}/js/jquery-2.1.4.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script>
    var get_user_name = function (user_id) {
        // var user_name = $.cookie('user_name_'+user_id);
        var user_name = window.localStorage.getItem('user_name_'+user_id);
        if(user_name){
            return user_name;
        }
        var user_name = '';
        $.ajax({
            url:"${base}/users_list/user_name",
            data:{
                "user_id":user_id,
            },
            type:"post",
            dataType:'json',
            async:false,//同步请求
            success:function (res) {
                user_name = res.data.user_name;
            },
            error:function (res) {

            }
        })
        // $.cookie('user_name_'+user_id, user_name, { expires: 7 });
        window.localStorage.setItem('user_name_'+user_id,user_name);
        return user_name;
    }

    var get_user_head = function (user_id) {
        // var user_head = $.cookie('user_head_'+user_id);
        var user_head = window.localStorage.getItem('user_head_'+user_id);
        if(user_head){
            return user_head;
        }
        var user_head = '';
        $.ajax({
            url:"${base}/users_list/user_head",
            data:{
                "user_id":user_id,
            },
            type:"post",
            dataType:'json',
            async:false,//同步请求
            success:function (res) {
                user_head =  res.data.user_header;
            },
            error:function (res) {

            }
        })
        // $.cookie('user_head_'+user_id, user_head, { expires: 7 });
        window.localStorage.setItem('user_head_'+user_id,user_head);
        return user_head;
    }

    var handle_call_list = function(list){
        $.each(list,function (k,v) {
            list[k]['user_name'] = get_user_name(v['targetId']);
            list[k]['user_head'] = get_user_head(v['targetId']);
        })
        return list;
    }
</script>
<script src="${base}/libs/utils.js"></script>
<script src="${base}/libs/qiniu-upload.js"></script>
<script src="${base}/template.js"></script>
<script src="${base}/emoji.js"></script>
<script src="${base}/im.js"></script>
<script src="${base}/init.js"></script>
<!-- 实例化 -->
<script>
    /*
     具体使用时：
     1：切换到自己的 key 和 token
     2：移除 im.js 里的 sendTextMessage(instance); 这行代码
     3：自行二次开发
     4：参考
     - 用户数据处理 http://support.rongcloud.cn/kb/NjQ5
     - 消息状态 http://support.rongcloud.cn/kb/NjMz
     - 集成指南 https://rongcloud.github.io/websdk-demo/integrate/guide.html
     - 其他 demo https://github.com/rongcloud/websdk-demo
     */
    (function(){
       /* var appKey = "3argexb6r934e";
        var token = "b/jvjEFD41TIVT0nsf9+L3ryPPkHsvRwWZV8SVI5ICcZ2I5Nl4OdNO01OjZxjjmVlD2dmk4RZ90=";*/

        var appKey = "${appKey}";
        var token = "${token}";
        RCS.init({
            appKey: appKey,
            token: token,
            target: document.getElementById('rcs-app'),
            showConversitionList: true,
            templates: {
                button: ['<div class="rongcloud-consult rongcloud-im-consult">',
                    '   <button onclick="RCS.showCommon()"><span class="rongcloud-im-icon">进入 IM</span></button>',
                    '</div>',
                    '<div class="customer-service" style="display: none;"></div>'].join('')//"templates/button.html",
//             chat: "templates/chat.html",
//             closebefore: 'templates/closebefore.html',
//             conversation: 'templates/conversation.html',
//             endconversation: 'templates/endconversation.html',
//             evaluate: 'templates/evaluate.html',
//             imageView: 'templates/imageView.html',
//             leaveword: 'templates/leaveword.html',
//             main: 'templates/main.html',
//             message: 'templates/message.html',
//             messageTemplate: 'templates/messageTemplate.html',
//             userInfo: 'templates/userInfo.html',
            },
            extraInfo: {
                // 当前登陆用户信息
                userInfo: {
                    name: "游客",
                    grade: "VIP"
                },
                // 产品信息
                requestInfo: {
                    productId: "123",
                    referrer: "10001",
                    define: "" // 自定义信息
                }
            }
        });
    })()


</script>

</html>